package com.yash.rms.domain;

import com.yash.rms.util.Constants;
import flexjson.JSONDeserializer;
import flexjson.JSONSerializer;
import flexjson.transformer.DateTransformer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.Transient;
import org.springframework.roo.addon.dbre.RooDbManaged;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord;
import org.springframework.roo.addon.json.RooJson;
import org.springframework.roo.addon.tostring.RooToString;
import org.springframework.web.multipart.MultipartFile;

@RooJavaBean
@RooJpaActiveRecord(versionField = "", table = "resource")
@RooDbManaged(automaticallyDelete = true)
@RooToString
@RooJson
public class Resource {

    @Transient
    private MultipartFile file;

    @Column(name = "resume_file_name", length = 256)
    private String resumeFileName;

    @OneToMany(mappedBy = "resourceId", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private Set<Timehrs> timehrss;

    public String getResumeFileName() {
        return resumeFileName;
    }

    public void setResumeFileName(String resumeFileName) {
        this.resumeFileName = resumeFileName;
    }

    public MultipartFile getFile() {
        return file;
    }

    public void setFile(MultipartFile file) {
        this.file = file;
    }

    public Set<com.yash.rms.domain.Timehrs> getTimehrss() {
        return timehrss;
    }

    public void setTimehrss(Set<com.yash.rms.domain.Timehrs> timehrss) {
        this.timehrss = timehrss;
    }

    public String toJson() {
        return new JSONSerializer().exclude("*.class").transform(new DateTransformer(Constants.DATE_PATTERN), Date.class).serialize(this);
    }

    public static com.yash.rms.domain.Resource fromJsonToResource(String json) {
        return new JSONDeserializer<Resource>().use(null, Resource.class).use(Date.class, new DateTransformer(Constants.DATE_PATTERN)).deserialize(json);
    }

    public static String toJsonArray(Collection<com.yash.rms.domain.Resource> collection) {
        return new JSONSerializer().exclude("*.class").transform(new DateTransformer(Constants.DATE_PATTERN), Date.class).serialize(collection);
    }

    public static Collection<com.yash.rms.domain.Resource> fromJsonArrayToResources(String json) {
        return new JSONDeserializer<List<Resource>>().use(null, ArrayList.class).use(Date.class, new DateTransformer(Constants.DATE_PATTERN)).use("values", Resource.class).deserialize(json);
    }
}
